<?php
declare(strict_types=1);

namespace app\common\service\sms\driver;

use app\common\service\sms\Driver;
use think\App;

class OnlyLog extends Driver
{
    protected $config = [
        'type' => 'OnlyLog',
        'handler_config' => [],
    ];
    protected $handler = null;

    public function __construct(App $app, array $config = [])
    {
        $this->config = array_merge($this->config, $config);

        // $this->handler = null;
    }

    /**
     * 发送短信
     * @param string $phone 手机号码
     * @param array $message 短信内容 
     * @return mixed
     */
    public function send(string $phone, array $message = [])
    {
        try {
            $sms_re = ['msg' => '短信模拟发送成功,详见日志'];

            // 记录日志
            $this->log($this->config['name'], $phone, $message);

            return $this->ok('发送短信成功', $sms_re);
        } catch (\Exception $e) {
            // 记录日志
            $this->log($this->config['name'], $phone, $message, $e->getMessage());
            return $this->fail('短信发送失败' . $e->getMessage());
        }
    }
}
